/**
 * 以下这段js代码主要功能为：在 x 秒单位内执行 clickElementEvent 次数达到 y 时，就会触发执行回调函数 callbackFn
 * @constructor
 */
function ClickCallback(){}
ClickCallback.prototype.clickCount = 0
ClickCallback.prototype.inTime = 3000
ClickCallback.prototype.targetCount = 10
ClickCallback.prototype.timer = null

ClickCallback.prototype.callbackFn = function() {
    console.log("以下这段js代码主要功能为：在 "+this.inTime/1000+" 秒单位内执行 clickElementEvent 次数达到 "+this.clickCount+" 时，就会触发执行回调函数 callbackFn")
    console.log("this is default callback function. Thanks for using this snip js")
}
/**
 * 点击事件或者执行其他事件
 */
ClickCallback.prototype.clickElementEvent = function() {
    this.clickCount++
    if (this.clickCount === 1) { // 第一次点击时，
        this.timer = setTimeout(() => {
            this.clickCount = 0
        }, this.inTime)
    }
    this.isReachTarget()
}
ClickCallback.prototype.isReachTarget = function() {
    if (this.clickCount >= this.targetCount) {
        if (typeof this.callbackFn === 'function') {
            this.callbackFn()
        }
        if (this.timer) {
            clearTimeout(this.timer)
        }
        this.clickCount = 0
    }
}
ClickCallback.prototype.setInTime = function(inTime) {
    this.inTime = inTime
}
ClickCallback.prototype.setTargetCount = function(targetCount) {
    this.targetCount = targetCount
}
ClickCallback.prototype.setTargetCount = function(targetCount) {
    this.targetCount = targetCount
}
